package com.common.utils;


import com.alibaba.fastjson.JSON;
import com.common.DateUtils;
import com.common.StringUtils;
import com.google.gson.Gson;
import com.hikvision.artemis.sdk.ArtemisHttpUtil;
import com.hikvision.artemis.sdk.config.ArtemisConfig;
import com.model.external.onecard.CardInfo;
import com.model.external.onecard.PersonDatas;
import com.model.external.onecard.ResourceInfos;
import com.model.external.onecard.Root;
import org.activiti.engine.impl.util.json.JSONObject;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.time.LocalDate;
import java.util.*;

/**
 * @ClassName HikVisionHelper
 * @Description 海康接口工具类
 * @Author admin
 * @Date 2020/12/17 14:07
 * @Version 1.0
 */
public class HikVisionHelper {


    private static final String PARK_NAME = "海科新源";
    private static final String PARK_SYSCODE = "09b183868fae435bbef87bb28e395c24";
    /**
     * STEP2：设置OpenAPI接口的上下文
     */
    private static final String ARTEMIS_PATH = "/artemis";
    private static Logger logger = LoggerFactory.getLogger(HikVisionHelper.class);
    private static Gson gson = new Gson();


    static {

        /**
         * STEP1：设置平台参数，根据实际情况,设置host appkey appsecret 三个参数.
         */
        ArtemisConfig.host = "192.168.17.108:443"; // artemis网关服务器ip端口
        ArtemisConfig.appKey = "22975079";  // 秘钥appkey
        ArtemisConfig.appSecret = "rlqFFEucJP50gDy6BY1E";// 秘钥appSecret

    }

    /**
     * 根据身份证获取海康里面的id
     * 如果返回空字符串说明本人在海康中不存在
     *
     * @param idCard
     * @return
     */
    public static Map<String, String> getPersionIdByIdcard(String idCard) {

        String personId = "";

        Map<String, String> infoMap = new HashMap();


        /**
         * STEP3：设置接口的URI地址
         */
        final String previewURLsApi = ARTEMIS_PATH + "/api/resource/v1/person/condition/personInfo";
        Map<String, String> path = new HashMap<String, String>(2) {
            {
                put("https://", previewURLsApi);//根据现场环境部署确认是http还是https
            }
        };

        /**
         * STEP4：设置参数提交方式
         */
        String contentType = "application/json";


        /**
         * STEP5：组装请求参数
         */
        JSONObject jsonBody = new JSONObject();

        jsonBody.put("paramName", "certificateNo");
        jsonBody.put("paramValue", idCard.split(","));

        String body = jsonBody.toString();


        /**
         * STEP6：调用接口
         */
        try {

            String result = ArtemisHttpUtil.doPostStringArtemis(path, body, null, null, contentType, null);// post请求application/json类型参数
            Map map = gson.fromJson(result, Map.class);
            Map dataMap = (Map) map.get("data");
            int total = (int) Double.parseDouble(dataMap.get("total") + "");
            if (total == 1) {
                //获取人员信息
                List<Map<String, Object>> list = (List<Map<String, Object>>) dataMap.get("list");
                personId = list.get(0).get("personId") + "";
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        infoMap.put("personId", personId);
        return infoMap;
    }

    /**
     * 根据personId获取卡号
     *
     * @param personId
     * @return
     */
    public static List<Map<String, Object>> getPersionCardNo(String personId) {


        //人员卡号
        String personCardNo = "";

        Map<String, String> infoMap = new HashMap();


        /**
         * STEP3：设置接口的URI地址
         */
        final String previewURLsApi = ARTEMIS_PATH + "/api/irds/v1/card/advance/cardList";
        Map<String, String> path = new HashMap<String, String>(2) {
            {
                put("https://", previewURLsApi);//根据现场环境部署确认是http还是https
            }
        };

        /**
         * STEP4：设置参数提交方式
         */
        String contentType = "application/json";


        /**
         * STEP5：组装请求参数
         */
        JSONObject jsonBody = new JSONObject();

        jsonBody.put("pageNo", 1);
        jsonBody.put("pageSize", 10);
        jsonBody.put("personIds", personId);


        String body = jsonBody.toString();


        /**
         * STEP6：调用接口
         */
        String result = ArtemisHttpUtil.doPostStringArtemis(path, body, null, null, contentType, null);// post请求application/json类型参数
        Map map = gson.fromJson(result, Map.class);
        Map dataMap = (Map) map.get("data");
        List<Map<String, Object>> list1 = (List<Map<String, Object>>) dataMap.get("list");
        if (list1.size() > 0) {
            personCardNo = list1.get(0).get("cardNo") + "";
        }
        //logger.info("卡号："+result);


        return list1;
    }

    /**
     * 添加人员信息
     *
     * @param personId
     * @param base64Pic
     * @param personName
     * @param gender
     * @param idCard
     * @return
     */
    public static String addPersion(String personId, String base64Pic, String personName, String gender, String idCard, String deptId) {


        /**
         * STEP3：设置接口的URI地址
         */
        final String previewURLsApi = ARTEMIS_PATH + "/api/resource/v1/person/single/add";
        Map<String, String> path = new HashMap<String, String>(2) {
            {
                put("https://", previewURLsApi);//根据现场环境部署确认是http还是https
            }
        };

        /**
         * STEP4：设置参数提交方式
         */
        String contentType = "application/json";

        /**
         * STEP5：组装请求参数
         */
        JSONObject jsonBody = new JSONObject();

        jsonBody.put("personId", personId);
        jsonBody.put("personName", personName);
        jsonBody.put("gender", gender);
        jsonBody.put("certificateType", "111");
        jsonBody.put("certificateNo", idCard);
        //组织机构
        jsonBody.put("orgIndexCode", deptId);
        Map<String, Object> map = new HashMap<>();
        String body = jsonBody.toString();
        String result = ArtemisHttpUtil.doPostStringArtemis(path, body, null, null, contentType, null);// post请求application/json类型参数

        map = gson.fromJson(result, Map.class);
        if ("success".equals(map.get("msg"))) {
            return map.get("data").toString();
        } else {
            logger.error("addPersionError==" + map.get("data"));
            return null;
        }

    }

    /**
     * 添加人员门禁权限
     *
     * @param personId
     * @param startTime 权限开始时间
     * @param endTime   权限结束时间
     * @return
     */
    public static boolean addPersionDoormPersion(String personId, String startTime, String endTime, String personType) {

        List<ResourceInfos> resourceIds = new ArrayList<>();
        ResourceInfos resourceInfo = new ResourceInfos();

        resourceInfo = new ResourceInfos();
        resourceInfo.setResourceIndexCode("71f7891d0a644acab1bc7439c10ac62d");
        resourceInfo.setResourceType("door");
        resourceInfo.setResourceIndexName("北围栏入口权限板_门_2");
        resourceIds.add(resourceInfo);

        resourceInfo = new ResourceInfos();
        resourceInfo.setResourceIndexCode("f0a95c94e7464709a130c78a96c0b24f");
        resourceInfo.setResourceType("door");
        resourceInfo.setResourceIndexName("北围栏入口权限板_门_1");
        resourceIds.add(resourceInfo);

        resourceInfo = new ResourceInfos();
        resourceInfo.setResourceIndexCode("dc0b77ac3b384c13913d1f4c5ca4a373");
        resourceInfo.setResourceType("door");
        resourceInfo.setResourceIndexName("北围栏出口_门_1");
        resourceIds.add(resourceInfo);

       /* resourceInfo = new ResourceInfos();
        resourceInfo.setResourceIndexCode("49ef0ff2ed3c4eb784111a673535c326");
        resourceInfo.setResourceType("door");
        resourceInfo.setResourceIndexName("北围栏入口_门_1");
        resourceIds.add(resourceInfo);

        resourceInfo = new ResourceInfos();
        resourceInfo.setResourceIndexCode("49ef0ff2ed3c4eb784111a673535c326");
        resourceInfo.setResourceType("door");
        resourceInfo.setResourceIndexName("北围栏入口_门_1");
        resourceIds.add(resourceInfo);
*/


        String contentType = "application/json";
/**
 * STEP6：调用接口
 */
        Root root = new Root();

        //权限有效时间(开始与结束日期要么都为空要么都不为空。配置人员权限的有效期，为空时默认长期有效)
        root.setStartTime(null);
        root.setEndTime(null);

        List<PersonDatas> setPersonDatas = new ArrayList<>();
        PersonDatas pd = new PersonDatas();

        List<String> indexCodesList = new ArrayList<>();
        indexCodesList.add(personId);

        pd.setIndexCodes(indexCodesList);
        pd.setPersonDataType("person");

        setPersonDatas.add(pd);

        root.setPersonDatas(setPersonDatas);
        root.setResourceInfos(resourceIds);

        //出入权限配置
        final String previewURLsApi2 = ARTEMIS_PATH + "/api/acps/v1/auth_config/add";
        Map<String, String> path2 = new HashMap<String, String>(2) {
            {
                put("https://", previewURLsApi2);//根据现场环境部署确认是http还是https
            }
        };

        /**
         * STEP5：组装请求参数
         */
        JSONObject jsonBody = new JSONObject(root);

        String body = jsonBody.toString();

        logger.info("body===" + body);

        /**
         * STEP6：调用接口
         */
        String result = ArtemisHttpUtil.doPostStringArtemis(path2, body, null, null, contentType, null);// post请求application/json类型参数

        //下载权限
        //出入权限配置
        final String previewURLsApi3 = ARTEMIS_PATH + "/api/acps/v1/authDownload/configuration/shortcut";
        Map<String, String> path3 = new HashMap<String, String>(2) {
            {
                put("https://", previewURLsApi3);//根据现场环境部署确认是http还是https
            }
        };

        /**
         * STEP5：组装请求参数
         */
        jsonBody = new JSONObject(resourceIds);
        jsonBody.put("taskType", 1);
        body = jsonBody.toString();

        /**
         * STEP6：调用接口
         */
        result = ArtemisHttpUtil.doPostStringArtemis(path3, body, null, null, contentType, null);// post请求application/json类型参数

        Map map = gson.fromJson(result, Map.class);
        if ("success".equals(map.get("msg"))) {
            logger.info("addPersionDoorSucce：" + map.get("msg"));
            return true;
        } else {
            logger.error("addPersionDoorError：" + map.get("msg"));
            return false;
        }
    }

    /**
     * 人员开卡
     *
     * @param personId
     * @param startTime 权限开始时间
     * @param endTime   权限结束时间
     * @return
     */
    public static boolean bindCards(String idCardNo, String personId, String startTime, String endTime, String deptId) {
        String contentType = "application/json";
        Root root = new Root();

        /**
         * 参数组建
         */
        //权限有效时间
        root.setStartDate(DateUtils.getCurrentDate());
        root.setEndDate("2037-01-01");
        List<CardInfo> cardInfoList = new ArrayList<>();
        CardInfo cardInfo = new CardInfo();
        // 卡号（此处为身份证号）
        cardInfo.setCardNo(idCardNo);
        cardInfo.setCardType("1");
        cardInfo.setPersonId(personId);
        cardInfo.setOrgIndexCode(deptId);
        cardInfoList.add(cardInfo);
        root.setCardList(cardInfoList);
        //人员开卡URL
        final String previewURLsApi2 = ARTEMIS_PATH + "/api/cis/v1/card/bindings";
        Map<String, String> path2 = new HashMap<String, String>(2) {
            {
                put("https://", previewURLsApi2);//根据现场环境部署确认是http还是https
            }
        };
        JSONObject jsonBody = new JSONObject(root);
        String body = jsonBody.toString();
        logger.info("body===" + body);
        /**
         * STEP6：调用接口
         */
        String result = ArtemisHttpUtil.doPostStringArtemis(path2, body, null, null, contentType, null);// post请求application/json类型参数
        if (StringUtils.isNullOrEmpty(result)) {
            return false;
        }else {
            Map map = gson.fromJson(result, Map.class);
            if ("0".equals(map.get("code"))) {
                logger.info("cardInfo:" + JSON.toJSONString(map));
                return true;
            } else {
                return false;
            }
        }

    }

    /**
     * 人员退卡
     *
     * @param cardNo   卡号
     * @param personId 海康人员io
     * @return
     */
    public static boolean deleteionCard(String cardNo, String personId) {
        if (StringUtils.isNullOrEmpty(cardNo) || StringUtils.isNullOrEmpty(personId)) {
            return false;
        }
        String contentType = "application/json";
        CardInfo cardInfo = new CardInfo();
        cardInfo.setCardNumber(cardNo);
        cardInfo.setPersonId(personId);
        //人员开卡URL
        final String previewURLsApi2 = ARTEMIS_PATH + "/api/cis/v1/card/deletion";
        Map<String, String> path2 = new HashMap<String, String>(2) {
            {
                put("https://", previewURLsApi2);//根据现场环境部署确认是http还是https
            }
        };
        JSONObject jsonBody = new JSONObject(cardInfo);
        String body = jsonBody.toString();
        logger.info("body===" + body);
        /**
         * STEP6：调用接口
         */
        String result = ArtemisHttpUtil.doPostStringArtemis(path2, body, null, null, contentType, null);// post请求application/json类型参数
        Map map = gson.fromJson(result, Map.class);
        if ("0".equals(map.get("code"))) {
            logger.info("cardInfo:" + JSON.toJSONString(map));
            return true;
        } else {
            return false;
        }
    }

    /**
     * 删除人员门禁权限
     *
     * @param personId
     * @param startTime 权限开始时间
     * @param endTime   权限结束时间
     * @return
     */
    public static boolean delPersionDoormPersion(String personId, String startTime, String endTime, String personType) {

        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        List<ResourceInfos> resourceIds = new ArrayList<>();
        ResourceInfos resourceInfo = new ResourceInfos();
        resourceInfo = new ResourceInfos();
        resourceInfo.setResourceIndexCode("71f7891d0a644acab1bc7439c10ac62d");
        resourceInfo.setResourceType("door");
        resourceInfo.setResourceIndexName("北围栏入口权限板_门_2");
        resourceIds.add(resourceInfo);

        resourceInfo = new ResourceInfos();
        resourceInfo.setResourceIndexCode("f0a95c94e7464709a130c78a96c0b24f");
        resourceInfo.setResourceType("door");
        resourceInfo.setResourceIndexName("北围栏入口权限板_门_1");
        resourceIds.add(resourceInfo);

        resourceInfo = new ResourceInfos();
        resourceInfo.setResourceIndexCode("dc0b77ac3b384c13913d1f4c5ca4a373");
        resourceInfo.setResourceType("door");
        resourceInfo.setResourceIndexName("北围栏出口_门_1");
        resourceIds.add(resourceInfo);

        resourceInfo = new ResourceInfos();
        resourceInfo.setResourceIndexCode("49ef0ff2ed3c4eb784111a673535c326");
        resourceInfo.setResourceType("door");
        resourceInfo.setResourceIndexName("北围栏入口_门_1");
        resourceIds.add(resourceInfo);
        String contentType = "application/json";
/**
 * STEP6：调用接口
 */
        Root root = new Root();

        //权限有效时间(开始与结束日期要么都为空要么都不为空。配置人员权限的有效期，为空时默认长期有效)
        root.setStartTime(null);
        root.setEndTime(null);

        List<PersonDatas> setPersonDatas = new ArrayList<>();
        PersonDatas pd = new PersonDatas();

        List<String> indexCodesList = new ArrayList<>();
        indexCodesList.add(personId);

        pd.setIndexCodes(indexCodesList);
        pd.setPersonDataType("person");

        setPersonDatas.add(pd);

        root.setPersonDatas(setPersonDatas);
        root.setResourceInfos(resourceIds);

        //出入权限配置
        final String previewURLsApi2 = ARTEMIS_PATH + "/api/acps/v1/auth_config/delete";
        Map<String, String> path2 = new HashMap<String, String>(2) {
            {
                put("https://", previewURLsApi2);//根据现场环境部署确认是http还是https
            }
        };

        /**
         * STEP5：组装请求参数
         */
        JSONObject jsonBody = new JSONObject(root);

        String body = jsonBody.toString();

        logger.info("body===" + body);

        /**
         * STEP6：调用接口
         */
        String result = ArtemisHttpUtil.doPostStringArtemis(path2, body, null, null, contentType, null);// post请求application/json类型参数

        Map map = gson.fromJson(result, Map.class);
        if ("success".equals(map.get("msg"))) {
            return true;
        } else {
            logger.error("delPersioError：" + result);
            return false;
        }
    }

    /**
     * 获取所有的门禁
     *
     * @return
     */
    public static List<Map<String, Object>> listAllRoom() {

/**
 * STEP3：设置接口的URI地址
 */
        final String previewURLsApi = ARTEMIS_PATH + "/api/irds/v2/deviceResource/resources";
        Map<String, String> path = new HashMap<String, String>(2) {
            {
                put("https://", previewURLsApi);//根据现场环境部署确认是http还是https
            }
        };

        /**
         * STEP4：设置参数提交方式
         */
        String contentType = "application/json";

        /**
         * STEP5：组装请求参数
         */
        JSONObject jsonBody = new JSONObject();

        jsonBody.put("pageNo", 1);
        jsonBody.put("pageSize", 100);
        jsonBody.put("resourceType", "door");

        String body = jsonBody.toString();

        /**
         * STEP6：调用接口
         */
        String result = ArtemisHttpUtil.doPostStringArtemis(path, body, null, null, contentType, null);// post请求application/json类型参数

        Gson g = new Gson();
        Map map = g.fromJson(result, Map.class);
        Map dataMap = (Map) map.get("data");
        List<Map<String, Object>> list1 = (List<Map<String, Object>>) dataMap.get("list");
        //用列表中的indexCode和name
        return list1;
    }

    /**
     * 删除用户信息
     *
     * @param personId
     * @return
     */
    public static boolean deletePersion(String personId) {


        /**
         * STEP4：设置参数提交方式
         */
        String contentType = "application/json";
        String result = "";


        /**
         * STEP3：设置接口的URI地址
         */
        final String previewURLsApi = ARTEMIS_PATH + "/api/resource/v1/person/batch/delete";
        Map<String, String> path = new HashMap<String, String>(2) {
            {
                put("https://", previewURLsApi);//根据现场环境部署确认是http还是https
            }
        };


        /**
         * STEP5：组装请求参数
         */
        JSONObject jsonBody = new JSONObject();

        jsonBody.put("personIds", personId.split(","));

        String body = jsonBody.toString();
        result = ArtemisHttpUtil.doPostStringArtemis(path, body, null, null, contentType, null);// post请求application/json类型参数


        Map map = gson.fromJson(result, Map.class);
        if ("success".equals(map.get("msg"))) {
            return true;
        } else {
            logger.error("deletePersionError" + result);
            return false;
        }

    }

    /**
     * 获取所有的人员记录
     *
     * @return
     */
    public static List<Map<String, Object>> listAllPersonRecord() {

        /**
         * STEP3：设置接口的URI地址
         */
        final String previewURLsApi = ARTEMIS_PATH + "/api/resource/v2/person/personList";
        Map<String, String> path = new HashMap<String, String>(2) {
            {
                put("https://", previewURLsApi);//根据现场环境部署确认是http还是https
            }
        };

        /**
         * STEP4：设置参数提交方式
         */
        String contentType = "application/json";


        int pageSize = 500;
        int allCount = 0;
        int pageNo = 1;
        List<Map<String, Object>> list = new ArrayList<>();
        do {

            /**
             * STEP5：组装请求参数
             */
            JSONObject jsonBody = new JSONObject();

            jsonBody.put("pageNo", pageNo);
            jsonBody.put("pageSize", pageSize);

            String body = jsonBody.toString();


            /**
             * STEP6：调用接口
             */
            String result = ArtemisHttpUtil.doPostStringArtemis(path, body, null, null, contentType, null);// post请求application/json类型参数
            Map map = gson.fromJson(result, Map.class);

            Map dataMap = (Map) map.get("data");
            allCount = (int) Double.parseDouble(dataMap.get("total") + "");

            List<Map<String, Object>> list1 = (List<Map<String, Object>>) dataMap.get("list");

            list.addAll(list1);

            pageNo++;

        } while (allCount > list.size());

        return list;
    }

    /**
     * 更新人员信息
     *
     * @return
     */
    public static List<Map<String, Object>> getPersonInfoByNo(String no) {

/**
 * STEP3：设置接口的URI地址
 */
        final String previewURLsApi = ARTEMIS_PATH + "/api/resource/v2/person/advance/personList";
        Map<String, String> path = new HashMap<String, String>(2) {
            {
                put("https://", previewURLsApi);//根据现场环境部署确认是http还是https
            }
        };

        /**
         * STEP4：设置参数提交方式
         */
        String contentType = "application/json";

        /**
         * STEP5：组装请求参数
         */
        JSONObject jsonBody = new JSONObject();

        List<Map<String, Object>> list = new ArrayList<>();
        Map<String, Object> m = new HashMap<>();
        m.put("key", "jobNo");
        m.put("operator", 0);
        m.put("values", no.split(","));

        list.add(m);

        jsonBody.put("pageNo", 1);
        jsonBody.put("pageSize", 1);
        jsonBody.put("expressions", list);


        String body = jsonBody.toString();

        /**
         * STEP6：调用接口
         */
        String result = ArtemisHttpUtil.doPostStringArtemis(path, body, null, null, contentType, null);// post请求application/json类型参数

        Gson g = new Gson();
        Map map = g.fromJson(result, Map.class);
        Map dataMap = (Map) map.get("data");
        List<Map<String, Object>> list1 = (List<Map<String, Object>>) dataMap.get("list");
        //用列表中的indexCode和name
        return list1;
    }

    /**
     * 更新人员信息
     *
     * @return
     */
    public static boolean updatePersonInfoById(String personId, String idcard) {

/**
 * STEP3：设置接口的URI地址
 */
        final String previewURLsApi = ARTEMIS_PATH + "/api/resource/v1/person/single/update";
        Map<String, String> path = new HashMap<String, String>(2) {
            {
                put("https://", previewURLsApi);//根据现场环境部署确认是http还是https
            }
        };

        /**
         * STEP4：设置参数提交方式
         */
        String contentType = "application/json";

        /**
         * STEP5：组装请求参数
         */
        JSONObject jsonBody = new JSONObject();

        jsonBody.put("personId", personId);
        jsonBody.put("certificateType", 111);
        jsonBody.put("certificateNo", idcard);

        String body = jsonBody.toString();

        /**
         * STEP6：调用接口
         */
        String result = ArtemisHttpUtil.doPostStringArtemis(path, body, null, null, contentType, null);// post请求application/json类型参数

        Map map = gson.fromJson(result, Map.class);
        if ("success".equals(map.get("msg"))) {
            return true;
        } else {
            logger.info(result);
            return false;
        }

    }

    /**
     * 根据人和卡号删除卡
     *
     * @param personId
     * @param cardNo
     * @return
     */
    public static boolean deleteCardInfoByInfo(String personId, String cardNo) {


        final String previewURLsApi = ARTEMIS_PATH + "/api/cis/v1/card/deletion";
        Map<String, String> path = new HashMap<String, String>(2) {
            {
                put("https://", previewURLsApi);//根据现场环境部署确认是http还是https
            }
        };

        /**
         * STEP4：设置参数提交方式
         */
        String contentType = "application/json";

        /**
         * STEP5：组装请求参数
         */
        JSONObject jsonBody = new JSONObject();

        jsonBody.put("personId", personId);
        jsonBody.put("cardNumber", cardNo);

        String body = jsonBody.toString();

        /**
         * STEP6：调用接口
         */
        String result = ArtemisHttpUtil.doPostStringArtemis(path, body, null, null, contentType, null);// post请求application/json类型参数

        Map map = gson.fromJson(result, Map.class);
        if ("success".equals(map.get("msg"))) {
            return true;
        } else {
            logger.info(result);
            return false;
        }

    }

    /**
     * 根据父级获取下级部门
     *
     * @return
     */
    public static List<Map<String, Object>> getOrgByParentOrgIndexCode() {

        //父级id
        String parentOrgIndexCode = "df9569c4-b35d-4f65-a5cd-a8c8bfe4f5db";

        final String previewURLsApi = ARTEMIS_PATH + "/api/resource/v1/org/parentOrgIndexCode/subOrgList";
        Map<String, String> path = new HashMap<String, String>(2) {
            {
                put("https://", previewURLsApi);//根据现场环境部署确认是http还是https
            }
        };

        /**
         * STEP4：设置参数提交方式
         */
        String contentType = "application/json";

        /**
         * STEP5：组装请求参数
         */
        JSONObject jsonBody = new JSONObject();

        jsonBody.put("parentOrgIndexCode", parentOrgIndexCode);
        jsonBody.put("pageNo", 1);
        jsonBody.put("pageSize", 1000);


        String body = jsonBody.toString();

        /**
         * STEP6：调用接口
         */
        String result = ArtemisHttpUtil.doPostStringArtemis(path, body, null, null, contentType, null);// post请求application/json类型参数

        Map map = gson.fromJson(result, Map.class);
        Map dataMap = (Map) map.get("data");
        List<Map<String, Object>> list1 = (List<Map<String, Object>>) dataMap.get("list");

        /*for(Map<String,Object> m : list1){
            System.out.println(m.get("orgIndexCode")+"=="+m.get("orgName"));
        }*/

        if ("success".equals(map.get("msg"))) {
            return list1;
        } else {
            logger.info(result);
            return Collections.emptyList();
        }

    }

    /**
     * 查询权限配置
     *
     * @param personId
     * @return
     */
    public static Map<String, String> getPerMiss(String personId) {

        Map<String, String> infoMap = new HashMap();
        Root root = new Root();
        List<PersonDatas> setPersonDatas = new ArrayList<>();
        PersonDatas pd = new PersonDatas();

        List<String> indexCodesList = new ArrayList<>();
        indexCodesList.add(personId);

        pd.setIndexCodes(indexCodesList);
        pd.setPersonDataType("person");

        setPersonDatas.add(pd);

        root.setPersonDatas(setPersonDatas);
        /**
         * STEP3：设置接口的URI地址
         */
        final String previewURLsApi = ARTEMIS_PATH + "/api/acps/v1/auth_config/search";
        Map<String, String> path = new HashMap<String, String>(2) {
            {
                put("https://", previewURLsApi);//根据现场环境部署确认是http还是https
            }
        };

        /**
         * STEP4：设置参数提交方式
         */
        String contentType = "application/json";


        /**
         * STEP5：组装请求参数
         */
        JSONObject jsonBody = new JSONObject(root);


        String body = jsonBody.toString();


        /**
         * STEP6：调用接口
         */
        try {

            String result = ArtemisHttpUtil.doPostStringArtemis(path, body, null, null, contentType, null);// post请求application/json类型参数
            Map map = gson.fromJson(result, Map.class);
            Map dataMap = (Map) map.get("data");
            int total = (int) Double.parseDouble(dataMap.get("total") + "");
            if (total == 1) {
                //获取人员信息
                List<Map<String, Object>> list = (List<Map<String, Object>>) dataMap.get("list");
                personId = list.get(0).get("personId") + "";
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        infoMap.put("personId", personId);
        return infoMap;
    }

}
